package com.qiangesoft.blog.controller.manage;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.qiangesoft.blog.common.annotation.OperationLog;
import com.qiangesoft.blog.common.mvc.PageQuery;
import com.qiangesoft.blog.common.mvc.PageResultVO;
import com.qiangesoft.blog.common.result.ResponseResult;
import com.qiangesoft.blog.core.entity.BlogCategory;
import com.qiangesoft.blog.core.service.IBlogCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 博客分类表 前端控制器
 * </p>
 *
 * @author qiange
 */
@RestController
@RequestMapping("/system/category")
@RequiredArgsConstructor
@Api(tags = "分类管理")
public class BlogCategoryController {

    private final IBlogCategoryService categoryService;

    @GetMapping(value = "/list")
    @SaCheckLogin
    @ApiOperation(value = "分类列表")
    public PageResultVO<BlogCategory> list(PageQuery pageQuery, String name) {
        return categoryService.listCategory(pageQuery, name);
    }

    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @ApiOperation(value = "分类详情", httpMethod = "GET", response = ResponseResult.class, notes = "分类详情")
    public ResponseResult getCategoryById(@RequestParam() Long id) {
        return categoryService.getCategoryById(id);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "新增分类", httpMethod = "POST", response = ResponseResult.class, notes = "新增分类")
    @OperationLog(value = "新增分类")
    public ResponseResult insertCategory(@RequestBody BlogCategory category) {
        return categoryService.insertCategory(category);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(value = "修改分类", httpMethod = "POST", response = ResponseResult.class, notes = "修改分类")
    @OperationLog(value = "修改分类")
    public ResponseResult update(@RequestBody BlogCategory category) {
        return categoryService.updateCategory(category);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除分类", httpMethod = "DELETE", response = ResponseResult.class, notes = "删除分类")
    @OperationLog(value = "删除分类")
    public ResponseResult deleteCategory(Long id) {
        return categoryService.deleteCategory(id);
    }

    @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除分类", httpMethod = "DELETE", response = ResponseResult.class, notes = "批量删除分类")
    @OperationLog(value = "批量删除分类")
    public ResponseResult deleteBatch(@RequestBody List<BlogCategory> list) {
        return categoryService.deleteBatch(list);
    }

    @RequestMapping(value = "/top", method = RequestMethod.GET)
    @ApiOperation(value = "置顶分类", httpMethod = "GET", response = ResponseResult.class, notes = "置顶分类")
    @OperationLog(value = "置顶分类")
    public ResponseResult top(Long id) {
        return categoryService.top(id);
    }
}

